﻿using ImageMagick;

using MyFleView.Core;
using PdfiumViewer;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyFileView.Core.Core
{

    /// <summary>
    /// 文件保存转化后 处理
    /// </summary>
    public class AfterConvertPathHandle
    {
        //  public List<string> Url { get; set; }
        public List<string> PathCollection = new List<string>();

        public ConvertFileInfo ConvertFileInfo { get; set; }


      //  public Dictionary<string,List<string>> PathCollectionDic=new Dictionary<string, List<string>>();
        /// <summary>
        /// 要跳转的界面
        /// </summary>
        public string Action { get; set; } = RouteConstant.Index;
        /// <summary>
        /// 
        /// </summary>
        public string Suffix { get; set; }
        //public bool IsCollection { get { return IsPathCollection; } }

        //private bool IsPathCollection { get; set; }

        //  public string UrlSuffix { get; set; }

        /// <summary>
        /// MagickImageCollection 转图片能用到
        /// </summary>
        /// <param name="magickImages"></param>
        public void SetCollection(MagickImageCollection magickImages)
        {
        
            PathCollection = magickImages.Select(x => x.FileName).ToList();
           // IsPathCollection = true;;
        }


        public int Width { get; set; } = 800;
        public int Height { get; set; } = 1000;

        public void SetCollection(string path)
        {
          //  PathCollectionDic.Add(path, new List<string>());
            PathCollection.Add(path);

        }

        public void SetCollection(string path,string action)
        {
            //  PathCollectionDic.Add(path, new List<string>());
            PathCollection.Add(path);
            Action= action;

        }
        /// <summary>
        /// 生成访问地址
        /// </summary>
        public  Func<string, List<string>, List<string>> Func=(x,y)=> y.Where((x) => x.Contains(x)).Select((y) => {
            int index = y.LastIndexOf(x);
            return y.Substring(index, y.Length - index).Replace("\\","/");

        }).ToList();
        public List<string> GenerateUrl() //string host
        {
            return Func(ConvertFileInfo.UrlSuffix, PathCollection);
            //if (PathCollection is null)
            //{
            //    PathCollection = new List<string>();
            //    SetCollection(ConvertFileInfo.FullFilePath);
            //    return  Func(urlSuffix,PathCollection);
            //}
            //else 
            //{
            //    return Func(urlSuffix, PathCollection);
            //}
            //foreach (var item in PathCollection)
            //{
            //    if (item.Contains(UrlSuffix))
            //    {
            //        int index = item.LastIndexOf(UrlSuffix);
            //        string url = item.Substring(index, item.Length - index);
            //        Url.Add(url);
            //    }
            //}
        }
    }
}
